package top.program.user.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.program.common.utils.MD5Utils;
import top.program.user.dao.UserMapper;
import top.program.user.entity.User;

import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import java.util.List;

@Service("UserServiceImpl")
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    @Transactional
    public void createUser(User user) throws UnsupportedEncodingException, NoSuchAlgorithmException {
        user.setPassword(MD5Utils.encryptPassword(user.getPassword()));
        userMapper.insert(user);
        }
    /**
      *@Author End_Search
      *@Date 2017/9/17 8:32
      *@Description 根据用户名查询用户
    */
    @Override
    public List<User> findUserByUserName(String userName) {
        List<User> userList = null;
        try {
            userList =userMapper.selectByUserName(userName);
        }catch (Exception e){
            e.printStackTrace();
            try {
                throw e;
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }
        return userList;
    }
}
